<template>
  <div class="login">
    <div class="title">
      <h1>医养综合服务信息系统</h1>
    </div>
    <div class="banner"></div>
    <div class="footer">
      <h2 style="font-size: 30px">LOGO</h2>
      <br />
      <h3 style="font-size: 20px">
        欢迎使用<span id="title">医养综合服务信息系统</span>
      </h3>
      <br />
      <el-form
        ref="ruleFormRef"
        style="max-width: 600px"
        :model="ruleForm"
        :rules="rules"
        label-width="auto"
        class="demo-ruleForm"
        :size="formSize"
        status-icon
      >
        <el-form-item prop="username" style="margin-bottom: 30px">
          <el-input
            v-model="ruleForm.username"
            placeholder="请输入账号"
            style="font-size: 20px; height: 50px"
          />
        </el-form-item>
        <el-form-item prop="phone" style="margin-bottom: 30px">
          <el-input
            v-model="ruleForm.phone"
            placeholder="请输入手机号码"
            style="font-size: 20px; height: 50px"
          />
        </el-form-item>
        <el-form-item prop="Code" style="margin-bottom: 30px">
          <el-button
            type="primary"
            style="height: 50px; width: 100px"
            @click="SendCode(ruleForm.phone)"
            >获取验证码</el-button
          >
          <el-input
            v-model="ruleForm.Code"
            placeholder="请输入验证码"
            style="font-size: 20px; height: 50px; width: 340px"
          />
        </el-form-item>

        <el-form-item prop="password" style="margin-bottom: 30px">
          <el-input
            v-model="ruleForm.password"
            placeholder="请输入密码"
            style="font-size: 20px; height: 50px"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            style="width: 100%"
            type="primary"
            size="large"
            @click="submitForm(ruleFormRef)"
          >
            找回密码
          </el-button>
        </el-form-item> </el-form
      ><br />
    </div>
  </div>
</template>
    
    <script setup>
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
import { findPassword, sendCode } from "../axios/Api/xsp_api";
import { ElMessage } from "element-plus";
const router = useRouter();
const formSize = ref("default");
const ruleFormRef = ref();
const ruleForm = reactive({
  username: "xspAdmin",
  password: "123456",
  phone: "17767230874",
  Code: "",
});
//验证码系列
const generatedCode = ref(""); //生成的验证码
const creationTime = ref(""); //验证码生成时间
const SendCode = async (phone) => {
  ElMessage({
    message: "验证码已发送",
    type: "success",
  });
  const { data } = await sendCode({ phone });
  generatedCode.value = data.code;
  creationTime.value = Date.now();
  console.log(generatedCode.value);
};
// 表单校验
const rules = {
  username: [{ required: true, message: "请输入账号", trigger: "blur" }],
  password: [{ required: true, message: "请输入密码", trigger: "blur" }],
  phone: [{ required: true, message: "请输入手机号码", trigger: "blur" }],
  Code: [{ required: true, message: "请输入验证码", trigger: "blur" }],
};

const submitForm = async (formEl) => {
  if (!formEl) return;
  await formEl.validate(async (valid, fields) => {
    if (valid) {
      const {
        data: { code, msg },
      } = await findPassword({
        username: ruleForm.username,
        password: ruleForm.password,
        phone: ruleForm.phone,
        code: ruleForm.Code, //输入的验证码
        generatedCode, //生成的验证码
        creationTime, //验证码生成时间
      });
      if (code == 200) {
        ElMessage({
          message: msg,
          type: "success",
        });
        router.push("/login");
      } else {
        ElMessage.error(msg);
      }
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>
    
    
    <style scoped>
* {
  padding: 0;
  margin: 0;
}
.login {
  width: 100%;
  height: 100%;
  position: relative;
}
.title {
  width: 95%;
  height: 20%;
  display: flex;
  justify-content: right;
  align-items: center;
}
h1 {
  color: #5676f7;
  font-style: italic;
  font-size: 50px;
}
.banner {
  width: 100%;
  height: 65%;
  background-image: url(../../public/1711072153790.jpg);
  background-size: 100% 100%;
  overflow: hidden;
  background-position: center;
  background-repeat: no-repeat;
}
.footer {
  box-sizing: border-box;
  box-shadow: 0 0 10px #5676f7;
  width: 25%;
  height: 65%;
  padding: 20px;
  position: absolute;
  top: 220px;
  left: 140px;
  background-color: #ffffff;
}
h2 {
  color: #5676f7;
}
#title {
  color: #5676f7;
}
</style>